/**
 * Created by dukes on 2016/3/11.
 */
class GuildWarehouse extends eui.Component{
    public constructor(){
        super();
        this.skinName = "skins.scene.GuilWarehouseSkin";
        // this.name = "guildWarehouse";
        // this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAdded, this );
        // this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoved, this);
    }
    // private onSelectedTab(evt:eui.IndexChangeEvent){
    //     SoundMgr.getInstance().playEffect(SoundMgr.BTN);
    //     this.shop_container.removeAllElements();
    //     this.group_guild.visible = this.group_mine.visible = false;
    //     if( this.lastSelectItem)
    //         this.lastSelectItem.setState("normal");
    //     this.lastSelectItem = null;
    //     if( evt.newIndex == 0){
    //         this.shop_container.addChild(GuildMaterialShop.getInstance());
    //         GuildMaterialShop.getInstance().setType(3);
    //         this.hehe_tab.visible = false;
    //         this.img_bg.x = 6;
    //         this.img_bg.width = 466;
    //         this.lab_lab.text = "威望:";
    //         this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().guildInfo.prestige,false, true);
    //     }else if( evt.newIndex == 1){
    //         this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().myMemberInfo.contribution,false, true);
    //         this.shop_container.addChild(GuildMaterialShop.getInstance());
    //         if( this.hehe_tab.selectedIndex == 0)
    //             GuildMaterialShop.getInstance().setType(4);
    //         else
    //             GuildMaterialShop.getInstance().setType(5);
    //         this.hehe_tab.visible = true;
    //         this.img_bg.x = 48;
    //         this.img_bg.width = 424;
    //         this.lab_lab.text = "贡献:";
    //     }
    // }
    // private onHeheTab(evt:eui.IndexChangeEvent){
    //     SoundMgr.getInstance().playEffect(SoundMgr.BTN);
    //     this.group_mine.visible = this.group_guild.visible = false;
    //     if( this.lastSelectItem)
    //         this.lastSelectItem.setState("normal");
    //     this.lastSelectItem = null;
    //     if( evt.newIndex == 0){
    //         GuildMaterialShop.getInstance().setType(4);
    //     }else if( evt.newIndex == 1){
    //         GuildMaterialShop.getInstance().setType(5);
    //     }
    // }

    // public onReturn(evt:egret.TouchEvent){
    //     SceneMgr.getInstance().switchScene(SceneMgr.SCENE_GUILD);
    // }

    // public onAdd(evt:egret.TouchEvent){
    //     var good = GuildMgr.getInstance().getGuildGoodById(this.lastSelectItem.curData.goodsId);
    //     var maxCnt = this.lastSelectItem.curData.count;
    //     var curCnt = parseInt(this.lab_unlock.text);
    //     curCnt++;
    //     curCnt = curCnt < maxCnt ? curCnt : maxCnt;
    //     this.lab_unlock.text = curCnt+"";
    //     this.lab_unlock_1.text = "可得威望 " +GetNumString(good.prestige*curCnt,false,true);

    // }
    // public onReduce(evt:egret.TouchEvent){
    //     var good = GuildMgr.getInstance().getGuildGoodById(this.lastSelectItem.curData.goodsId);
    //     var curCnt = parseInt(this.lab_unlock.text);
    //     curCnt--;
    //     if( curCnt < 0 )
    //         curCnt=1;
    //     this.lab_unlock.text = curCnt+"";
    //     this.lab_unlock_1.text = "可得威望 " +GetNumString(good.prestige*curCnt,false,true);
    // }
    // public onMax(evt:egret.TouchEvent){
    //     var good = GuildMgr.getInstance().getGuildGoodById(this.lastSelectItem.curData.goodsId);
    //     var data = this.lastSelectItem.curData;
    //     this.lab_unlock.text = data.count+"";
    //     this.lab_unlock_1.text = "可得威望 " +GetNumString(good.prestige*data.count,false,true);
    // }
    // public onBuy(evt:egret.TouchEvent){
    //     var cnt = parseInt(this.lab_unlock.text);
    //     if( cnt != 0)
    //         window["__exchangePrestige"](this.lastSelectItem.curData.goodsId,cnt);
    // }
    // public onDonate(evt:egret.TouchEvent){
    //     var cnt = parseInt(this.lab_3.text);
    //     if( cnt != 0  && this.lastSelectItem && this.lastSelectItem.curData  && this.lastSelectItem.curData.goodsId){
    //         if(this.lastSelectItem.curData.type == 2){
    //             window["__donateGoods"](this.lastSelectItem.curData.goodsId,cnt);
    //         }else if( this.lastSelectItem.curData.type == 3){
    //             window["__sellMaterial"](this.lastSelectItem.curData.goodsId,cnt);
    //         }
    //     }
    // }
    // public onAdd1(evt:egret.TouchEvent){
    //     var maxCnt = this.lastSelectItem.curData.count;
    //     var good = GuildMgr.getInstance().getGuildGoodById(this.lastSelectItem.curData.goodsId);
    //     var curCnt = parseInt(this.lab_3.text);
    //     curCnt++;
    //     curCnt = curCnt < maxCnt ? curCnt : maxCnt;
    //     this.lab_3.text = curCnt+"";
    //     this.lab_1.text = "贡献+" +GetNumString(good.contribution*curCnt,false,true);
    // }
    // public onReduce1(evt:egret.TouchEvent){
    //     var curCnt = parseInt(this.lab_3.text);
    //     var good = GuildMgr.getInstance().getGuildGoodById(this.lastSelectItem.curData.goodsId);
    //     curCnt--;
    //     if( curCnt < 0 )
    //         curCnt=1;
    //     this.lab_3.text = curCnt+"";
    //     this.lab_1.text = "贡献+" +GetNumString(good.contribution*curCnt,false,true);
    // }
    // public onMax1(evt:egret.TouchEvent){
    //     var data = this.lastSelectItem.curData;
    //     this.lab_3.text = data.count+"";
    //     var good = GuildMgr.getInstance().getGuildGoodById(this.lastSelectItem.curData.goodsId);
    //     this.lab_1.text = "贡献+" +GetNumString(good.contribution*data.count,false,true);
    // }

    // private onAdded(evt:egret.Event){
    //     this.img_return.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onReturn, this);
    //     this.fuck_tab.addEventListener(eui.IndexChangeEvent.CHANGE, this.onSelectedTab, this);
    //     this.hehe_tab.addEventListener(eui.IndexChangeEvent.CHANGE, this.onHeheTab, this);
    //     EventController.getInstance().addEventListener(EventController.WAREHOUSE_ITEM_SELECTED,this.onShopItem, this);
    //     this.add_unlock.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onAdd, this);
    //     this.reduce_unlock.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onReduce, this);
    //     this.max_unlock.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onMax, this);
    //     this.buy_unlock.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBuy, this);


    //     this.buy_1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onDonate, this);
    //     this.add_1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onAdd1, this);
    //     this.reduce_1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onReduce1, this);
    //     this.max_1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onMax1, this);
    //     if( this.flag ){
    //         this.shop_container.addChild(GuildMaterialShop.getInstance());
    //         if( this.fuck_tab.selectedIndex == 0){
    //             this.lab_lab.text = "威望:";
    //             this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().guildInfo.prestige,false, true);
    //             GuildMaterialShop.getInstance().setType(3);
    //         }else if( this.hehe_tab.selectedIndex == 0){
    //             this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().myMemberInfo.contribution,false, true);
    //             this.lab_lab.text = "贡献:";
    //             GuildMaterialShop.getInstance().setType(4);
    //         }else{
    //             this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().myMemberInfo.contribution,false, true);
    //             this.lab_lab.text = "贡献:";
    //             GuildMaterialShop.getInstance().setType(5);
    //         }
    //     }
    // }
    // private onRemoved(evt:egret.Event){
    //     this.img_return.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onReturn, this);
    //     this.fuck_tab.removeEventListener(eui.IndexChangeEvent.CHANGE, this.onSelectedTab, this);
    //     this.hehe_tab.removeEventListener(eui.IndexChangeEvent.CHANGE, this.onHeheTab, this);
    //     EventController.getInstance().removeEventListener(EventController.WAREHOUSE_ITEM_SELECTED,this.onShopItem, this);
    //     this.add_unlock.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onAdd, this);
    //     this.reduce_unlock.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onReduce, this);
    //     this.max_unlock.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onMax, this);
    //     this.buy_unlock.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onBuy, this);

    //     this.buy_1.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onDonate, this);
    //     this.add_1.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onAdd1, this);
    //     this.reduce_1.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onReduce1, this);
    //     this.max_1.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onMax1, this);
    // }
    // private lastSelectItem:FuckItem;
    // private onShopItem(evt:egret.Event){
    //     if( this.lastSelectItem){
    //         this.lastSelectItem.setState("normal");
    //     }
    //     this.lastSelectItem = evt.data;
    //     this.lastSelectItem.setState("select");
    //     this.updateShopItemRelated(this.lastSelectItem.curData);
    // }
    // private updateShopItemRelated(data){
    //     if( data == null){
    //         this.group_mine.visible = this.group_guild.visible = false;
    //         return;
    //     }
    //     if(data.type == 1 && data.goodsId != 0){
    //         this.group_guild.visible = true;
    //         this.group_mine.visible = false;
    //         this.updateGuildGroup(data);
    //     }else if( data.goodsId != 0 && (data.type == 2 || data.type == 3)){
    //         this.group_guild.visible = false;
    //         this.group_mine.visible = true;
    //         this.updateMyGroup(data);
    //     }else{
    //         this.group_mine.visible = this.group_guild.visible = false;
    //         if( (data.type == 2 || data.type == 3) && data.state == 0){
    //             if( data.type == 2)
    //                 RemindPanel.getInstance().showContent("是否花费"+GuildMgr.getInstance().unlockWareHouseCost[Model.userExt.unlockProductBoxTimes]+"钻石解锁5个格子?", this, this.onBuyGrid);
    //             else if( data.type == 3)
    //                 RemindPanel.getInstance().showContent("是否花费"+GuildMgr.getInstance().unlockWareHouseCost[Model.userExt.unlockMaterialBoxTimes]+"钻石解锁5个格子?", this, this.onBuyGrid);
    //         }
    //     }
    // }
    // private onBuyGrid(){
    //     window["__unlockBox"](this.lastSelectItem.curData.type);
    // }
    // private updateGuildGroup(data){
    //     var good:GoodInfo = Model.GetGoodInfoById(data.goodsId);
    //     this.icon_unlock.source = GameConst.Res_Root + "resource/assets/items/" + good.id + ".png";
    //     this.lab_name_unlock.text = good.name;
    //     this.lab_unlock.text = "1";
    //     this.lab_unlock_1.text = "可得威望" + GuildMgr.getInstance().getGuildGoodById(this.lastSelectItem.curData.goodsId).prestige;
    // }

    // private updateMyGroup(data){
    //     var good:GoodInfo = Model.GetGoodInfoById(data.goodsId);
    //     this.icon_1.source = GameConst.Res_Root + "resource/assets/items/" + good.id + ".png";
    //     this.lab_name_1.text = good.name;
    //     this.lab_1.text = "贡献+" + GuildMgr.getInstance().getGuildGoodById(this.lastSelectItem.curData.goodsId).contribution;
    //     this.lab_3.text = "1";
    //     if( data.type==2){
    //         this.buy_1.source = RES.getRes("img_fuck_guild_15");
    //     }else if( data.type == 3){
    //         this.buy_1.source = RES.getRes("img_fuck_guild_56");
    //     }
    // }

    // public img_return:eui.Image;
    // public fuck_tab:eui.TabBar;
    // public hehe_tab:eui.TabBar;
    // private shop_container:eui.Group;
    // private group_guild:eui.Group;
    // private group_mine:eui.Group;

    // private icon_unlock:eui.Image;
    // private add_unlock:eui.Image;
    // private reduce_unlock:eui.Image;
    // private max_unlock:eui.Image;
    // private buy_unlock:eui.Image;
    // private lab_unlock:eui.Label;
    // private lab_unlock_1:eui.Label;
    // private lab_name_unlock:eui.Label;
    // private lab_unlock_2:eui.BitmapLabel;

    // private icon_1:eui.Image;
    // private add_1:eui.Image;
    // private reduce_1:eui.Image;
    // private max_1:eui.Image;
    // private buy_1:eui.Image;
    // private lab_name_1:eui.Label;
    // private lab_1:eui.Label;
    // private lab_3:eui.Label;

    // private img_bg:eui.Image;
    // private lab_lab:eui.Label;
    // public partAdded(name:string, instance:any) {
    //     super.partAdded(name, instance);
    //     if (name == "fuck_tab") {
    //         this.fuck_tab = instance;
    //         this.fuck_tab.itemRenderer = new eui.ClassFactory(GuildShopTab);
    //         this.fuck_tab.dataProvider = new eui.ArrayCollection([2,3]);
    //     }else if (name == "hehe_tab") {
    //         this.hehe_tab = instance;
    //         this.hehe_tab.itemRenderer = new eui.ClassFactory(WarehouseTab);
    //         this.hehe_tab.dataProvider = new eui.ArrayCollection([0,1]);
    //     }else if (name == "lab_lab") {
    //         this.lab_lab = instance;
    //     }else if (name == "img_bg") {
    //         this.img_bg = instance;
    //     }else if (name == "lab_1") {
    //         this.lab_1 = instance;
    //     }else if (name == "lab_3") {
    //         this.lab_3 = instance;
    //     }else if (name == "icon_1") {
    //         this.icon_1 = instance;
    //     }else if (name == "add_1") {
    //         this.add_1 = instance;
    //     }else if (name == "reduce_1") {
    //         this.reduce_1 = instance;
    //     } else if (name == "max_1") {
    //         this.max_1 = instance;
    //     }else if (name == "buy_1") {
    //         this.buy_1 = instance;
    //     }else if (name == "lab_name_1") {
    //         this.lab_name_1 = instance;
    //     } else if (name == "shop_container") {
    //         this.shop_container = instance;
    //     }else if (name == "img_return") {
    //         this.img_return = instance;
    //     }else if (name == "lab_name_unlock") {
    //         this.lab_name_unlock = instance;
    //     }else if (name == "icon_unlock") {
    //         this.icon_unlock = instance;
    //     }else if (name == "add_unlock") {
    //         this.add_unlock = instance;
    //     }else if (name == "reduce_unlock") {
    //         this.reduce_unlock = instance;
    //     }else if (name == "max_unlock") {
    //         this.max_unlock = instance;
    //     }else if (name == "buy_unlock") {
    //         this.buy_unlock = instance;
    //         this.buy_unlock.visible = GuildMgr.getInstance().guildInfo.shaikhId == Model.me.id;
    //     }else if (name == "lab_unlock") {
    //         this.lab_unlock = instance;
    //     }else if (name == "lab_unlock_1") {
    //         this.lab_unlock_1 = instance;
    //     } else if (name == "lab_unlock_2") {
    //         this.lab_unlock_2 = instance;
    //     }else if (name == "group_guild") {
    //         this.group_guild = instance;
    //     }else if (name == "group_mine") {
    //         this.group_mine = instance;
    //     }
    // }
    // private flag;
    // public childrenCreated(){
    //     super.childrenCreated();
    //     this.shop_container.addChild(GuildMaterialShop.getInstance());
    //     GuildMaterialShop.getInstance().setType(3);
    //     this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().guildInfo.prestige,false, true);
    //     this.flag = true;
    // }
    // public onExchangeBack(){
    //     this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().guildInfo.prestige,false, true);
    //     this.updateShopItemRelated(this.lastSelectItem.curData);
    // }
    // public onDonateBack(){
    //     this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().myMemberInfo.contribution,false, true);
    //     this.updateShopItemRelated(this.lastSelectItem.curData);
    // }
    private static _instance:GuildWarehouse;
    public static getInstance():GuildWarehouse{
        if( GuildWarehouse._instance == null)
            GuildWarehouse._instance = new GuildWarehouse();
        return GuildWarehouse._instance;
    }
}